package forumTransform.forumTransformID;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class ResultFileWriter{
			
	private String filename;
	private FileOutputStream fop = null;
	private File file;
	private String content = "";
	private String extension;
	
	public final static String OUTPUT_EXTENSION = ".out.txt";
	

	public ResultFileWriter(String filename) {
		super();
		this.filename = filename;
	}
	
	public ResultFileWriter(String filename, String content) {
		super();
		this.filename = filename;
		this.content = content;
		this.extension = OUTPUT_EXTENSION;
	}
	
	public ResultFileWriter(String filename, String content, String extension) {
		super();
		this.filename = filename;
		this.content = content;
		this.extension = extension;
	}
	
	public void persist (){
		try {
			//file = new File("out/"+filename+extension);
			file = new File("C:\\Users\\Dan\\workspace\\forumTransformID\\out\\"+filename+extension);
			fop = new FileOutputStream(file);
			// if file doesnt exists, then create it
			if (!file.exists()) {
				file.createNewFile();
			}
			// get the content in bytes
			byte[] contentInBytes = content.getBytes();
			fop.write(contentInBytes);
			fop.flush();
			fop.close();
			System.out.println("File "+filename+extension+ " written OK!"); 
		}  catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		 catch (Exception e) {
				e.printStackTrace();
		 }
	}
	public String getFilename() {
		return filename;
	}
	
	public void setFilename(String filename) {
		this.filename = filename;
	}
	
	public FileOutputStream getFop() {
		return fop;
	}
	
	public void setFop(FileOutputStream fop) {
		this.fop = fop;
	}
	
	public File getFile() {
		return file;
	}
	
	public void setFile(File file) {
		this.file = file;
	}
	
	public String getContent() {
		return content;
	}
	
	public void setContent(String content) {
		this.content = content;
	}
}
